﻿using Ekton_Manage_DomainCore.Aggregate;
using Ekton_Manage_DTO.RequestModels.User;
using Ekton_Manage_Framework.Methods;
using Ekton_Manage_Framework.Redis;
using Ekton_Manage_IBusiness;
using Ekton_Manage_InfrastructureCore.Common;
using Ekton_Manage_InfrastructureCore.Repositories;
using Ekton_Manage_Mapper.EntityMappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Ekton_Manage_Business
{
    class SelectAdvertList : ISelectAdvertList
    {
        private readonly SerializeParameter _serialize;
        private readonly IBaseRepository<space_configuration, int> _baseMaterialRepository;
        public SelectAdvertList(IBaseRepository<space_configuration, int> baseMaterialRepository, SerializeParameter serialize)
        {
            _baseMaterialRepository = baseMaterialRepository;
            _serialize = serialize;
        }

        /// <summary>
        /// 查询广告
        /// </summary>
        /// 
        public async Task<Tuple<List<space_configuration>, int>> QueryAdvertList(QueryDataParame query)
        {
            var dicData = await _serialize.ParameConvertToDict(query.parame);
            Expression<Func<space_configuration, bool>> expression = m => true;

            return await _baseMaterialRepository.QueryPageData(query, expression);

        }


        /// 
        /// <summary>
        /// 修改广告
        /// </summary>
        /// 
        public async Task<Message> PutAdvertList(DtoInsertSpaceConfiguration requset)
        {
            var sysUserList = await _baseMaterialRepository.QuerySingleData(requset.id);
            if (sysUserList == null) return new Message(false, 202);
            sysUserList.picture = requset.picture;
            sysUserList.path = requset.path;
            sysUserList.state = requset.state;
            var result = await _baseMaterialRepository.UpdateSingleData(sysUserList);
            return new Message(result.Item1);
        }

        /// <summary>
        /// 添加广告
        /// </summary>
        /// 
        public async Task<Message> PostAdvertList(DtoInsertSpaceConfiguration request)
        {
            var list = await _baseMaterialRepository.InsertSingleData(new space_configuration
            {
                picture = request.picture,
                path = request.path,
                state = "0"
            });
            return new Message(list.Item1);
        }

        /// <summary>
        /// 删除广告
        /// </summary>
        /// 
        public async Task<Message> DeleteAdvertList(int id)
        {
            var list = await _baseMaterialRepository.DeleteSingleData(id);
            return new Message(true, 200);
        }

    }
}
